IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[SelectAllTraslado]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[SelectAllTraslado]
GO

CREATE PROCEDURE [dbo].[SelectAllTraslado]

AS
BEGIN
	SET NOCOUNT ON

	SELECT
	T.[trasladoID],
	T.[loteID],
	T.[origenAlmacenID],
	T.[destinoAlmacenID],
	T.[cantidad],
	T.[fecha],
	T.[personalID],
	L.insumoID,
	L.numero AS lote,
	I.nombre AS insumo,
	A1.nombre AS almacenOrigen,
	A2.nombre AS almacenDestino
	FROM [Traslado] AS T
	INNER JOIN Lotes AS L ON T.loteID = L.loteID
	INNER JOIN Insumos AS I ON L.insumoID = I.insumoID
	INNER JOIN Almacenes AS A1 ON T.origenAlmacenID = A1.almacenID
	INNER JOIN Almacenes AS A2 ON T.destinoAlmacenID = A2.almacenID
	
	SET NOCOUNT OFF
END

GO
